package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.CountByTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {

    @Autowired
    private CustomerReservationService customerReservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
        Integer count = customerReservationService.getCancelledReservationCount(userId);
        return success(count);
    }

    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult addReservation(@RequestBody ReservationDto reservationDto){
        customerReservationService.addReservation(reservationDto);
        return success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public ResponseResult getByPage(Integer pageNum,Integer pageSize,Integer status){
        PageResponse response = customerReservationService.getByPage(pageNum,pageSize,status);
        return success(response);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult cancelReservation(@PathVariable Integer id){
        customerReservationService.cancelReservation(id);
        return success();
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult getCountByTime(@RequestParam Long time){
        List<CountByTimeVo> list = customerReservationService.getCountByTime(time);
        return success(list);
    }
}